package com.wangzh.data;

public class ListNode {

    private Integer value;

    public Integer getValue() {
        return value;
    }

    public static ListNode of(int ... ints){

        ListNode s = new ListNode(-1,null);
        ListNode p =s;
        for (int anInt : ints) {
            ListNode listNode = new ListNode(anInt, null);
            p.next=listNode;
            p=listNode;
        }
        return s.next;
    }
    public void setValue(Integer value) {
        this.value = value;
    }

    public ListNode getNext() {
        return next;
    }

    public void setNext(ListNode next) {
        this.next = next;
    }

    private ListNode next;

    public ListNode(Integer value, ListNode next) {
        this.value = value;
        this.next = next;
    }

    @Override
    public String toString() {

        StringBuilder sb = new StringBuilder();
        sb.append("[");

        ListNode p = this;
        while (p!=null){
            sb.append(p.value);
            if (p.next!=null){
                sb.append(",");
            }
            p = p.next;
        }
        sb.append("]");
        return sb.toString();
    }
}
